﻿using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pongster
{
    class DrawablePhysicsCircle
    {
        public const float unitToPixel = 60f;
        public const float pixelToUnit = 1 / unitToPixel;
 
        public Body Body;

        public Texture2D texture;

        public Color color = Color.White;

        public Vector2 Position
        {
            get { return Body.Position * unitToPixel; }
            set { Body.Position = value * pixelToUnit; }
        }

        public DrawablePhysicsCircle(World world, Texture2D texture, float radius, float density)
        {
            Body = BodyFactory.CreateCircle(
                world, 
                radius * pixelToUnit, 
                1
            );

            Body.BodyType = BodyType.Dynamic;
            Body.SleepingAllowed = true;
 
            this.texture = texture;
        }
 
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(
                texture, 
                Position, 
                null,
                color, 
                Body.Rotation, 
                new Vector2(texture.Width / 2.0f, texture.Height / 2.0f), 
                1.0f, 
                SpriteEffects.None, 
                0
            );
        }


    }
}